﻿
@{
    ViewData["Title"] = "添加用户";
    Layout = "_Operate";
}
@model Admin.Model.SysUser
<div class="main-content">
    <form id="form-user-edit" class="form-horizontal">
        <input name="Id" type="hidden" asp-for="Id" />
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>用户名称：</label>
                    <div class="col-sm-8">
                        <input name="Name" asp-for="Name" placeholder="请输入用户名称" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>手机号码：</label>
                    <div class="col-sm-8">
                        <input name="Phone" asp-for="Phone" placeholder="请输入手机号码" class="form-control" type="text" maxlength="11" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>登录账号：</label>
                    <div class="col-sm-8">
                        <input name="Account" asp-for="Account" id="Account" placeholder="请输入登录账号" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">角色：</label>
                    <div class="col-sm-8">
                        <select name="RoleId" class="form-control">
                            @foreach (var item in ViewBag.Roles)
                            {
                                <option value="@item.Id">@item.CName</option>
                            }
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户性别：</label>
                    <div class="col-sm-8">
                        <select name="Sex" asp-for="Sex" class="form-control">
                            <option value="2">未知</option>
                            <option value="0">男</option>
                            <option value="1">女</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>邮箱：</label>
                    <div class="col-sm-8">
                        <input name="Email" asp-for="Email" class="form-control email" type="text" maxlength="50" placeholder="请输入邮箱" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户状态：</label>
                    <div class="col-sm-8">
                        <div class="radio-box">
                            <input type="radio" name="Status" value="0">
                            <label>启用</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" name="Status" value="1">
                            <label>停用</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">其他信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="Remark" asp-for="Remark" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

@*<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>*@
@section Scripts{
    <script type="text/javascript">
        $(function () {
            $("input:radio[name=Status][value=" + @Model.Status + "]").iCheck("check");
            $("select[name=RoleId]").val(@ViewBag.RoleId);

            $("#form-user-edit").validate({
            onkeyup: false,
            rules: {
                Email: {
                    email: true,
                    remote: {
                        url: "/api/SysUser/CheckEmail",
                        type: "get",
                        dataType: "json",
                        data: {
                            Id: function () {
                                return $.common.trim($("#Id").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return data == "false";
                        }
                    }
                },
                Phone: {
                    isPhone: true,
                    remote: {
                        url: "/api/SysUser/CheckPhone",
                        type: "get",
                        dataType: "json",
                        data: {
                            Id: function () {
                                return $.common.trim($("#Id").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return data == "false";
                        }
                    }
                },
            },
            messages: {
                "Email": {
                    remote: "Email已经存在"
                },
                "Phone": {
                    remote: "手机号码已经存在"
                }
            },
            focusCleanup: true
            });
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $.common.formToJSON("form-user-edit");
                data["Id"] = parseInt(data["Id"]);
                data["RoleId"] = parseInt(data["RoleId"]);
                $.operate.saveTab("/api/SysUser/EditSave", JSON.stringify(data));
            }
        }
    </script>
}
